package com.qidian.server.messages;

import java.io.UnsupportedEncodingException;

import com.qidian.server.messages.plugin2server.NumberTakingMessage;
import com.qidian.util.ByteUtil;

public abstract class Message
{
    public static String charSet = "UTF-8" ;
    
    public static int msg_type_0 = 0 ;
    public static int msg_type_1 = 1 ;
    
    
    
    /**
     *  将消息装换成字节数组，用于发送
     * 
     * */
    public abstract int toBytes(byte[] content, int offset, int length) ; 
    
    
    /**
     * 将字节数据解析成消息
     * @throws UnsupportedEncodingException 
     * 
     * */
    public static Message toMessage(byte[] message, int offset, int length) throws UnsupportedEncodingException
    {

        int msg_type = ByteUtil.readInt(message,offset) ;
        if (msg_type == msg_type_0)
            return NumberTakingMessage.toMessage(message,offset,length) ;
        if (msg_type == msg_type_1)
            return null ;

        return null ;
    }
    
    public abstract boolean isValid() ;
}
